from datetime import datetime
from datetime import timedelta
import pytz

class Time:
    @staticmethod
    def getUTC8DateTime():
        # 设置东八区时区
        eastern_eight_time_zone = pytz.timezone('Asia/Shanghai')

        # 获取并设置当前时间为东八区时间
        eastern_eight_time = datetime.now(eastern_eight_time_zone)
        return eastern_eight_time

    @staticmethod
    def deltaTime(seconds: int):
        return timedelta(seconds=seconds)
    
    @staticmethod
    def format(time: datetime):
        return time.strftime('%Y-%m-%d %H:%M:%S')

    '''
    东八区 到第二天 0 点的秒数
    单位: s
    '''
    @staticmethod
    def getTimeToNextDay():
        now_s = int(Time.getUTC8Timestamp() / 1000)
        nextDay = int(now_s / 60 / 60 / 24) + 1
        nextDay_s = nextDay * 24 * 60 * 60 - now_s - 60 * 60 * 8 # 还要再减去 8 个小时
        return nextDay_s
    

    '''
    东八区时间戳
    单位: ms
    '''
    @staticmethod
    def getUTC8Timestamp():
        utc8Time = Time.getUTC8DateTime()
        res = int(utc8Time.timestamp() * 1000)
        return res